ValidationController = null;

_ValidationController = function(){
	this.ValidationStack = [];
	this.Result = null;
}
_ValidationController.prototype = {
		GetNewValidationItem: function() {
				return {
					Func: null,/*<--------rule (function) for validation*/
					Item: {}/*<--------item for validation*/
				};
		},
		AddValidationItemToStack: function(item) {
				this.ValidationStack.push(item);
				return this;
		},
		AddValidationItemToStackByIndex: function(item, index) {
			this.ValidationStack.splice(index, 0, item);
			return this;
		},
		CreateAndAddValidationItemToStack: function(item, func, index) {
				var valItem = this.GetNewValidationItem();
				valItem.Item = item;
				valItem.Func = func;
				if(!index || index<0) {
					this.AddValidationItemToStack(valItem);
				}
				else {
					this.AddValidationItemToStackByIndex(valItem, index);
				}
				return this;
		},
		Validate: function(){
			var result = false;
			for (var key in this.ValidationStack) {
	            var item = this.ValidationStack[key];
	            /*----------this function calculate result for each rule without general result context--------------------*/
	            (function(){
	            	var localRes = false;
	            	localRes = item.Func(item.Item);
	            	result = localRes;
	            }).call(this);
	            /*---------------------------------------------------------------------------------------------------------*/
	            if(!result){
	            	break;
	            }
	        }
			this.Result = result;
			return this;
		},
		ValidateAndCleanStack: function(){
			this.Validate();
			this.ValidationStack = [];
			return this;
		}
}
/*--------------this section describe validation rules-----------------*/
/*example:
 * function equaltominusone(item){
 *	var result = false;
 *		result  = (item == -1);
 *		return result;
 *	}
 * */
/*
 * item - item for validate
 * */
function equaltominusone(item){
	var result = false;
		result  = (item == -1);
	return result;
}
function isNullOrEmpty(item){
	var result = false;
		result  = (!item || item == "");
	return result;
}
